package hc.um.action;

import hc.um.service.UserService;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class QureyDrugsServlet
 */
@WebServlet("/QureyDrugsServlet")
public class QureyDrugsServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	private UserService userService = new UserService();

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public QureyDrugsServlet() {
		super();
		// TODO Auto-generated constructor stub
	}

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		System.out.println("query drugs list------------get------------");
		this.getDrugsList(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		System.out.println("query drugs list");
		this.getDrugsList(request, response);
	}

	public void getDrugsList(HttpServletRequest request,
			HttpServletResponse response) throws IOException {
		String res = userService.getDrugRecords();
		System.out.println("durg list= " + res);
		response.getWriter().write(res);
	}
}
